using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Reception : System.Web.UI.Page
{
	private DateTime _mWeddingDate = new DateTime(2006, 11, 18);
	private string _mAddress = 
		"http://www.mapquest.com/directions/main.adp?go=1&do=nw&rmm=1&un=m" +
		"&cl=EN&qq=m4ZeC4eEaUh9FRgxf%252bvPukWjbU43ytdRvH3ALF4FnpqZFuS%252b" +
		"e3bKAw8vRriP9Fcu8yHi6PG0JPxBu3HhAel72u%252fc%252f5GnKzxw13USsnCddqB" +
		"v%252bwCja9p2smUAhumA9isejPgFcr3Dr7gcaLH5ZDytG0gVERmKu5w1Q2jRu1J1r0" +
		"o%252bvz5kYZdlT4kL20GExIP657lMeNTfi7yXrFs6W1wHZ%252fa1cDCYiYkTZN%252" +
		"bQ7GVtDT4LlDwrMG0RhA%253d%253d&ct=NA&rsres=1&1y=US&1ffi=&1l=&1g=&1pl" +
		"=&1v=&1n=&1pn=&1a=$Address$&1c=$City$&1s=$State$&1z=$Zip$&pa" +
		"nelbtn=1&2y=US&2ffi=&2l=fTTMHWyNpC4%252ff01D4d1ydA%253d%253d&2g=aM8I" +
		"B0RHUfiHkcwi%252fzxCFQ%253d%253d&2pl=&2v=ADDRESS&2n=&2pn=&2a=1150+Co" +
		"le+Rd+Sw&2c=Lilburn&2s=GA&2z=30047-5426";

	private const string ADDRESS = "$Address$";
	private const string CITY = "$City$";
	private const string STATE = "$State$";
	private const string ZIP = "$Zip$";

	protected void Page_Load(object sender, EventArgs e)
	{
		TimeSpan days;

		if (!IsPostBack)
		{
			//is the date after the wedding date?
			if (DateTime.Now > _mWeddingDate) //Yes
			{
				days = DateTime.Now.Subtract(_mWeddingDate);
				lblDaysAfter.Text = (days.TotalDays - 1).ToString("n0");
				pnlAfter.Visible = true;
				pnlBefore.Visible = false;
			}
			else
			{
				days = _mWeddingDate.Subtract(DateTime.Now);
				lblDaysBefore.Text = (days.TotalDays + 1).ToString("n0");
			}
		}
	}

	protected void lnkDirections_Click(object sender, EventArgs e)
	{
		pnlOptions.Visible = false;
		pnlDirectionInput.Visible = true;
	}

	protected void btnCancel_Click(object sender, EventArgs e)
	{
		pnlOptions.Visible = true;
		pnlDirectionInput.Visible = false;
	}

	protected void btnDirections_Click(object sender, EventArgs e)
	{
		string address = _mAddress.Replace(ADDRESS, Server.UrlEncode(txtAddress.Text));

		address = address.Replace(CITY, Server.UrlEncode(txtCity.Text));

		address = address.Replace(STATE, Server.UrlEncode(txtState.Text));

		address = address.Replace(ZIP, Server.UrlEncode(txtZip.Text));

		ClientScript.RegisterStartupScript(this.GetType(), "directions", 
			"window.open('" + address + "', '', '');", true);

		pnlOptions.Visible = true;
		pnlDirectionInput.Visible = false;
	}
}
